class Polygon {
  constructor(opt) {
    let opts = Object.assign({}, opt);
    this.path = opts.path;
    this.icon = opts.icon;
    let ns = opts.path.map((p) => {
      return p[1];
    });
    let ew = opts.path.map((p) => {
      return p[0];
    });
    this.north = Math.max(...ns);
    this.south = Math.min(...ns);
    this.east = Math.max(...ew);
    this.west = Math.min(...ew);
  }

  getRectByPolygon(Map) {
    let lt = Map.lngLatToContainer([this.west, this.north]);
    let rb = Map.lngLatToContainer([this.east, this.south]);
    let mx = (this.east + this.west) / 2;
    let my = (this.north + this.south) / 2;
    // let m = Map.lngLatToContainer([mx, my]);
    return {
      lng: this.west,
      lat: this.north,
      lt: lt,
      rb: rb,
      width: Math.abs(rb.x - lt.x),
      height: Math.abs(rb.y - lt.y),
      mx: mx,
      my: my,
    };
  } // 获取多边形对象相对地图视窗的像素坐标和像素尺寸，参数：地图对象
}

export { Polygon };
